package com.autoplaza;

import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;

public class Utils    {
    public static void CopyStream(InputStream is, OutputStream os)
    {
        final int buffer_size=1024;
        try
        {
            byte[] bytes=new byte[buffer_size];
            for(;;)
            {
              int count=is.read(bytes, 0, buffer_size);
              if(count==-1)
                  break;
              os.write(bytes, 0, count);
            }
        }
        catch(Exception ex){}
    }
    
    
    public static int getScreenSize2(Activity a){
		DisplayMetrics displayMetrics = a.getResources().getDisplayMetrics();
		float densityBucketDpi = displayMetrics.densityDpi;
		Log.i("densityBucketDpi", ""+densityBucketDpi);
    	int returnvalue = 0;
//    	int[] dimen = new int[2];
//    	Display display = a.getWindowManager().getDefaultDisplay(); 
//    	dimen[0] = display.getWidth();
//    	dimen[1] = display.getHeight();
//    	if(dimen[0] <= 320){
//        	Log.i("DENSITY", "MEDIUM");
//        	returnvalue = 1;
//    	}else if( (dimen[0] > 320) && (dimen[0] <=480 )){
//        	Log.i("DENSITY", "HIGH");
//        	returnvalue = 2;
//    	}else if(dimen[0] > 480){
//        	Log.i("DENSITY", "EXTRA HIGH");
//        	returnvalue = 3;
//
//    	}
//    	Log.i("WIDTH", ""+dimen[0]);
//    	Log.i("HEIGHT", ""+dimen[1]);
    	if(densityBucketDpi <= 170){
        	Log.i("DENSITY", "MEDIUM");
        	returnvalue = 1;
    	}else if(densityBucketDpi > 170 && densityBucketDpi <=250){
    		Log.i("DENSITY", "HIGH");
        	returnvalue = 2;
    	}else if(densityBucketDpi >= 250 ){
        	Log.i("DENSITY", "EXTRA HIGH");
        	returnvalue = 3;
    	}
    	
    	return returnvalue;
    }
    
    public static int[] getScreenSize(Activity a){
    	int[] dimen = new int[2];
    	Display display = a.getWindowManager().getDefaultDisplay(); 
    	dimen[0] = display.getWidth();
    	dimen[1] = display.getHeight();
    	if(dimen[0] <= 320){
        	Log.i("DENSITY", "MEDIUM");
    	}else if( (dimen[0] > 320) && (dimen[0] <=480 )){
        	Log.i("DENSITY", "HIGH");
    	}else if(dimen[0] > 480){
        	Log.i("DENSITY", "EXTRA HIGH");
    	}
    	Log.i("WIDTH", ""+dimen[0]);
    	Log.i("HEIGHT", ""+dimen[1]);
    	return dimen;
    }
    
	//CHECA LA CONEXION A INTERNET
	public static boolean isOnline(Context ctx) {
		NetworkInfo networkInfo = ((ConnectivityManager) ctx
	              .getSystemService(Context.CONNECTIVITY_SERVICE))
	              .getActiveNetworkInfo();

	            if(networkInfo == null || !networkInfo.isConnected()) {
	             return false;
	            }
	            return true;
	}
    
}